package com.decent.ejfadmin.user.service.impl;


import com.decent.ejfadmin.common.bean.MessageBean;
import com.decent.ejfadmin.common.bean.Page;
import com.decent.ejfadmin.user.dao.UserPmDao;
import com.decent.ejfadmin.user.service.UserPmService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
 * 会员专属管理员
 *
 * @author weicx
 * @date 2018/08/15
 */
@Service
@Slf4j
public class UserPmServiceImpl implements UserPmService {
    @Autowired
    private UserPmDao userPmDao;

    /**
     * 修改专属商务
     *
     * @param id        专属id
     * @param status    操作，0新增，1修改
     * @param adminName 商务名称，可空
     * @param qq        联系qq，可空
     * @param tel       联系电话，可空
     * @return 修改行数
     */
    @Override
    public MessageBean modifyUserPm(Integer id, Integer status, String adminName, String qq, String tel)  {
        switch (status) {
            case 0:
                if (userPmDao.createUserPm(adminName, qq, tel) > 0) {
                    return MessageBean.success();
                }
            case 1:
                if (userPmDao.modifyUserPm(id, adminName, qq, tel) > 0) {
                    return MessageBean.success();
                }
            default:
                return MessageBean.fail();
        }
    }


    /**
     * 删除专属商务
     *
     * @param id 专属id，可空
     * @return 成功“OK”
     */
    @Override
    public MessageBean deleteUserPm(Integer id) {
        if (userPmDao.deleteUserPm(id) == 0) {
            return MessageBean.fail();
        }
        return MessageBean.success();
    }

    /**
     * 查询专属商务
     *
     * @param adminName 查询商务，可空
     * @param page      分页
     * @return MemberMessage
     */
    @Override
    public Page queryUserPm(Page page, String adminName) {
        int total = userPmDao.queryUserPmCount(adminName);
        page.setTotal(total);
        if (total == 0) {
            page.setResultList(new ArrayList<>());
        } else {
            page.setResultList(userPmDao.queryUserPmPage(page, adminName));
        }
        return page;
    }


}
